package docmanager.operation.documentos;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import docmanager.business.objects.Sector;
import docmanager.business.objects.TipoDocumento;
import docmanager.db.ConnectionPool;

import bf.operation.Operation;
import bf.operation.OperationException;

public class OpAgregarDocumento1 extends Operation {

	@Override
	public Map execute(HttpServletRequest request) throws OperationException {
		Map m = new HashMap();
		m.put("accion", "alta");
		try {
			Connection conn = ConnectionPool.getConnection();
			// Levantamos los tipo de documentos.
			List<TipoDocumento> tiposDoc = TipoDocumento.obtenerTodosTipos(conn);
			// Levantamos los sectores.
			List<Sector> sectores = Sector.obtenerTodosLosSectores(conn);
			m.put("tiposDoc", tiposDoc);
			m.put("sectores", sectores);
			ConnectionPool.closeConn(conn);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			throw new OperationException();
		}		
	    System.out.println("Terminamos de cargar todo");
		return m;
	}

	@Override
	public String getReturnURL() {
		// TODO Auto-generated method stub
		return "Documentos/AMDocumento.jsp";
	}

}
